package com.chennan.algorithm.leetcode.eleven;

import java.util.List;

/**
 * @author chennan
 * @create 2021-10
 */
public class MergeTwoLists {

    public static void main(String[] args) {

    }
    public static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode listNode = new ListNode();
        ListNode headNode = listNode;
        while(l1!=null&&l2!=null){
            if(l1.val>=l2.val){
                listNode.next = l2;
                l2=l2.next;
            }else{
                listNode.next = l1;
                l1=l1.next;
            }
            listNode = listNode.next;
        }
        listNode.next=l1==null?l2:l1;
        return headNode.next;
    }

}


class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
